package krow.dev.contest.view;

import java.util.ArrayList;
import java.util.List;

import krow.dev.contest.R;
import krow.dev.contest.model.ContestItem;
import krow.dev.contest.model.FavoriteItem;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class FavoriteListAdapter extends BaseAdapter {

	private List<FavoriteItem> mFavoriteList;

	private LayoutInflater mLayoutInflater;

	public FavoriteListAdapter(Context context) {

		mFavoriteList = new ArrayList<FavoriteItem>();

		mLayoutInflater = LayoutInflater.from(context);
	}

	public void setFavoriteItemList(List<FavoriteItem> favoriteItemList) {

		mFavoriteList.clear();
		mFavoriteList.addAll(favoriteItemList);
	}

	@Override
	public int getCount() {

		return mFavoriteList.size();
	}

	@Override
	public Object getItem(int position) {

		return mFavoriteList.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		System.out.println("페보릿리스트아답터 - " + getCount());

		final FavoriteItem favoriteItem = mFavoriteList.get(position);

		View view = mLayoutInflater.inflate(R.layout.drawer_favoritelist, null);
		view.setTag(favoriteItem);

		TextView titleView = (TextView) view.findViewById(R.id.text_title);
		titleView.setText(favoriteItem.getTitle());
		titleView.setSelected(true);

		TextView departmentView = (TextView) view
				.findViewById(R.id.text_department);
		departmentView.setText(favoriteItem.getDepartment());

		TextView creatorView = (TextView) view.findViewById(R.id.text_creator);
		creatorView.setText(favoriteItem.getCreator());

		return view;

	}

}
